import Vue from 'vue'
import App from '@/App.vue'
import router from '@/router'
import i18n from '@/i18n'
import * as echarts from 'echarts'
import '@/assets/js/elementui'
import '@/assets/css/index.scss'
import config from '@/config'
import '@/service/axios'
import '@/service/util'
import '@/utils/flexible'
import store from '@/store'
import '@/service/message.bus'
import dataV from '@jiaminghi/data-view'
import commonmixins from '@/utils/commonmixins'
import filterCharacter from '@/directives/filterCharacter.js'
import { handleServiceI18n } from '@/service/i18n'
import { handleEmpty } from '@/utils/common.js'
import './assets/css/font-icon/iconfont.css'

// 暂无数据
import NullData from '@/components/NullData.vue'
Vue.component('NullData', NullData)

Vue.prototype.$echarts = echarts
Vue.prototype.$utils = {
  handleServiceI18n,
  handleEmpty
}
Vue.mixin(commonmixins)
Vue.use(dataV)
filterCharacter.install(Vue)
Vue.prototype.$config = config
Vue.prototype.yes = true
Vue.prototype.no = false
Vue.config.productionTip = false

// 添加tabs
router.beforeEach((to, from, next) => {
  // console.log(to, from)
  const CUR_ROUTENAME = localStorage.getItem('OEN_CUR_ROUTENAME')
  console.log('CUR_ROUTENAME-------', CUR_ROUTENAME)
  if (CUR_ROUTENAME) {
    localStorage.removeItem('OEN_CUR_ROUTENAME')
    next({ path: CUR_ROUTENAME })
  } else {
    if (to.name === 'ERROR404') {
      next()
    } else {
      if (to.name && to.path) {
        const item = {
          label: to.name,
          name: to.name,
          path: to.path
        }
        store.commit('addActivedTabs', item)
      }
      next()
    }
  }
})

const vue = new Vue({
  i18n,
  router,
  store,
  render: h => h(App)
}).$mount('#app')

export default vue
